//package gw.com.android.ui.quote2;
//
//import android.annotation.SuppressLint;
//import android.support.v4.app.FragmentActivity;
//import android.view.View;
//import android.view.ViewGroup;
//
//import com.gwtsz.gts2.hx.R;
//
//import gw.com.android.app.GTConfig;
//import www.com.library.app.Logger;
//
///**
// * 行情引导页;
// *
// * 3.2版本，行情界面大改。这个引导页基本也没什么作用了
// *
// * @author jett
// * @since 2017-08-29.
// */
//public class QuoteGuideLayer {
//
//    private static final String TAG = "QuoteGuideLayer";
//    private static final String FIRST_LAYER = "quote_first_layer";
//    private static final String SECOND_LAYER = "quote_second_layer";
//
//    private static final QuoteGuideLayer instance = new QuoteGuideLayer();
//
//    private boolean firstShowed = false;// 第一层已经显示完成
//    private boolean secondShowed = false;// 第二层已经显示完成
//
//    private boolean layerIsShowing = false; // 有引导层正在显示中...
//
//    public static QuoteGuideLayer getInstance() {
//        return instance;
//    }
//
//    public void run(final NewQuoteFragment fragment) {
//        Logger.i(TAG, "run..");
//        if (firstShowed && secondShowed) {
//            Logger.i(TAG, "all layeres has already showed..");
//            return;
//        }
//        if (layerIsShowing) {
//            return;
//        }
//        if (fragment == null || fragment.getActivity() == null) {
//            Logger.i(TAG, "fragment or activity is null.");
//            return;
//        }
//        firstShowed = isLayerShowed(FIRST_LAYER);
//        if (!firstShowed) {
//            showFirst(fragment);
//            return;
//        }
//        secondShowed = isLayerShowed(SECOND_LAYER);
//        if (!secondShowed) {
//            showSecond(fragment);
//        }
//    }
//
//    private void setLayerShowed(String key, boolean showed) {
//        GTConfig.instance().setBooleanValue(key, showed);
//    }
//
//    private boolean isLayerShowed(String key) {
//        return GTConfig.instance().getBooleanValue(key, false);
//    }
//
//    public void resetLayer() {
//        setLayerShowed(FIRST_LAYER, false);
//        setLayerShowed(SECOND_LAYER, false);
//    }
//
//    /**
//     * 展示第一层引导
//     */
//    @SuppressLint("RtlHardcoded")
//    private void showFirst(final NewQuoteFragment fragment) {
//        Logger.i(TAG, "show first");
//        if (fragment == null || fragment.getActivity() == null || fragment.getActivity().isFinishing()) {
//            Logger.i(TAG, "show first.  fragment is null or activity is finishing..");
//            return;
//        }
//        FragmentActivity activity = fragment.getActivity();
//        View view = View.inflate(activity, R.layout.view_quote_first_guide, null);
//
//        view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Logger.i(TAG, "first layer clicked");
//                remove(v);
//                layerIsShowing = false;
//                showSecond(fragment);
//            }
//        });
//
//        final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
//        decorView.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
//
//        setLayerShowed(FIRST_LAYER, true);
//        layerIsShowing = firstShowed = true;
//        Logger.i(TAG, "first layer showed");
//    }
//
//    private void showSecond(final NewQuoteFragment fragment) {
//        Logger.i(TAG, "show second.");
//        if (secondShowed) {
//            Logger.i(TAG, "second was showed.");
//            return;
//        }
//        if (fragment == null || fragment.getActivity() == null || fragment.getActivity().isFinishing()) {
//            Logger.i(TAG, "show second.  fragment is null or activity is finishing..");
//            return;
//        }
////        final RecyclerView recyclerView = fragment.getRecyclerView();
////        if (recyclerView == null || recyclerView.getAdapter() == null) {
////            Logger.i(TAG, "show second. recyclerView is null or adapter is null");
////            return;
////        }
////        int count = fragment.getRecyclerViewDataCount();
////        if (count <= 0) {
////            Logger.i(TAG, "show second. item is empty.  count = " + count);
////            return;
////        }
////        FragmentActivity activity = fragment.getActivity();
////        if (activity instanceof MainActivity) {
////            MainActivity mActivity = (MainActivity) activity;
////            if (!ConfigType.TAB_QUOTE_TAG.equals(mActivity.mCurrentTag)) {
////                // 只有首页展示行情的时候，才显示引导页
////                Logger.i(TAG, "show second. isNext tab is not quote. ");
////                return;
////            }
////        }
////        if (recyclerView.getMeasuredWidth() <= 0) {
////            Logger.i(TAG, "show second. waitting for layout finish.");
////            recyclerView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
////                @Override
////                public void onGlobalLayout() {
////                    recyclerView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
////                    showSecond(fragment);
////                }
////            });
////            return;
////        }
////        int index = count - 1 > 2 ? 2 : count - 1;
////        View child = recyclerView.getChildAt(index);
////        if (child == null) {
////            Logger.i(TAG, "show second. child is null.  index = " + index);
////            return;
////        }
////        int[] location = new int[2];
////        child.getLocationInWindow(location);
////        int childHeight = child.getMeasuredHeight();
////        Logger.i(TAG, "show second. child height = " + childHeight + "  child y = " + location[1]);
////
////        View view = View.inflate(activity, R.layout.view_quote_second_guide, null);
////
////        View mask1 = view.findViewById(R.id.iv_mask1);
////        ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mask1.getLayoutParams();
////        params.topMargin = location[1];
////        params.height = childHeight;
////        mask1.setLayoutParams(params);
//
////        View shadow = view.findViewById(R.id.shadow1);
////        ViewGroup.LayoutParams layoutParams = shadow.getLayoutParams();
////        layoutParams.height = location[1];
////        shadow.setLayoutParams(layoutParams);
////
////        view.setOnClickListener(new View.OnClickListener() {
////            @Override
////            public void onClick(View v) {
////                remove(v);
////                layerIsShowing = false;
////                FMGuideLayer.getInstance().run(fragment, R.id.fm_float_view);
////            }
////        });
//
////        final ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
////        decorView.addView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
////
////        setLayerShowed(SECOND_LAYER, true);
////        layerIsShowing = secondShowed = true;
////        Logger.i(TAG, "second layer showed");
//    }
//
//    private static void remove(final View view) {
//        ViewGroup parent = (ViewGroup) view.getParent();
//        if (parent != null) {
//            parent.removeView(view);
//        }
//    }
//
//}